1 /*
2  * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation version 2.1 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
17  *
18  * Described at ETSI EN 300 468 V1.11.1 (2010-04)
19  */
20 
21 /**
22  * @file desc_ca.h
23  * @ingroup descriptors
24  * @brief Provides the descriptors for Conditional Access
25  * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1)
26  * @author Andre Roth
27  *
28  * @par Relevant specs
29  * The descriptor described herein is defined at:
30  * - ETSI EN 300 468 V1.11.1 (2010-04)
31  *
32  * @see http://www.etherguidesystems.com/help/sdos/mpeg/semantics/mpeg-2/descriptors/CA_descriptor.aspx
33  *
34  * @par Bug Report
35  * Please submit bug reports and patches to linux-media@vger.kernel.org
36  */
37 
38 module libdvbv5_d.desc_ca;
39 
40 import libdvbv5_d.descriptors: dvb_desc;
41 import libdvbv5_d.dvb_fe: dvb_v5_fe_parms;
42 
43 extern (C):
44 
45 /**
46  * @struct dvb_desc_ca
47  * @ingroup descriptors
48  * @brief Contains the private data for Conditional Access
49  *
50  * @param type			descriptor tag
51  * @param length		descriptor length
52  * @param next			pointer to struct dvb_desc
53  * @param ca_id			Conditional Access ID
54  * @param ca_pid		Conditional Access ID
55  * @param privdata		pointer to private data buffer
56  * @param privdata_len		length of the private data
57  */
58 struct dvb_desc_ca
59 {
60     align (1):
61 
62     ubyte type;
63     ubyte length;
64     dvb_desc* next;
65 
66     ushort ca_id;
67 
68     union
69     {
70         align (1):
71 
72         ushort bitfield1;
73 
74         struct
75         {
76             import std.bitmanip : bitfields;
77             align (1):
78 
79             mixin(bitfields!(
80                 ushort, "ca_pid", 13,
81                 ushort, "reserved", 3));
82         }
83     }
84 
85     ubyte* privdata;
86     ubyte privdata_len;
87 }
88 
89 // struct dvb_v5_fe_parms;
90 
91 /** @brief initial descriptor field at dvb_desc_ca struct */
92 // enum dvb_desc_ca_field_first = ca_id;
93 /** @brief last descriptor field at dvb_desc_ca struct */
94 // enum dvb_desc_ca_field_last = privdata;
95 
96 /**
97  * @brief Initializes and parses the CA descriptor
98  * @ingroup descriptors
99  *
100  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
101  * @param buf	buffer containing the descriptor's raw data
102  * @param desc	pointer to struct dvb_desc to be allocated and filled
103  *
104  * This function allocates a the descriptor and fills the fields inside
105  * the struct. It also makes sure that all fields will follow the CPU
106  * endianness. Due to that, the content of the buffer may change.
107  *
108  * @return On success, it returns the size of the allocated struct.
109  *	   A negative value indicates an error.
110  */
111 int dvb_desc_ca_init (
112     dvb_v5_fe_parms* parms,
113     const(ubyte)* buf,
114     dvb_desc* desc);
115 
116 /**
117  * @brief Prints the content of the CA descriptor
118  * @ingroup descriptors
119  *
120  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
121  * @param desc	pointer to struct dvb_desc
122  */
123 void dvb_desc_ca_print (dvb_v5_fe_parms* parms, const(dvb_desc)* desc);
124 
125 /**
126  * @brief Frees all data allocated by the CA descriptor
127  * @ingroup descriptors
128  *
129  * @param desc pointer to struct dvb_desc to be freed
130  */
131 void dvb_desc_ca_free (dvb_desc* desc);